import { request } from '@/utils/request'
import type {
  RestaurantMark,
  CreateMarkDto,
  PaginatedMarks,
  RestaurantMarkCheck,
  MarkStats,
  PaginationParams,
  ApiResponse
} from './types'

/**
 * 餐厅标记相关API
 */
export const markApi = {
  /**
   * 创建餐厅标记
   * @param data 标记数据
   */
  createMark(data: CreateMarkDto) {
    return request.post<ApiResponse<RestaurantMark>>('/marks', data)
  },

  /**
   * 标记今天不想吃
   * @param restaurantId 餐厅ID
   */
  markToday(restaurantId: string) {
    return request.post<ApiResponse<RestaurantMark>>(`/marks/today/${restaurantId}`, {})
  },

  /**
   * 标记本周不想吃
   * @param restaurantId 餐厅ID
   */
  markWeek(restaurantId: string) {
    return request.post<ApiResponse<RestaurantMark>>(`/marks/week/${restaurantId}`, {})
  },

  /**
   * 获取所有标记（分页）
   * @param pagination 分页参数
   */
  getMarks(pagination?: PaginationParams) {
    return request.get<ApiResponse<PaginatedMarks>>('/marks', pagination)
  },

  /**
   * 获取活跃的标记（未过期）
   */
  getActiveMarks() {
    return request.get<ApiResponse<RestaurantMark[]>>('/marks/active')
  },

  /**
   * 获取今天的标记
   */
  getTodayMarks() {
    return request.get<ApiResponse<RestaurantMark[]>>('/marks/today')
  },

  /**
   * 获取本周的标记
   */
  getWeekMarks() {
    return request.get<ApiResponse<RestaurantMark[]>>('/marks/week')
  },

  /**
   * 获取指定餐厅的标记
   * @param restaurantId 餐厅ID
   */
  getRestaurantMarks(restaurantId: string) {
    return request.get<ApiResponse<RestaurantMark[]>>(`/marks/restaurant/${restaurantId}`)
  },

  /**
   * 检查餐厅是否被标记
   * @param restaurantId 餐厅ID
   * @param markType 标记类型
   */
  checkRestaurantMark(restaurantId: string, markType?: 'today' | 'week') {
    const params = markType ? { markType } : {}
    return request.get<ApiResponse<RestaurantMarkCheck>>(`/marks/check/${restaurantId}`, params)
  },

  /**
   * 删除标记
   * @param id 标记ID
   */
  deleteMark(id: string) {
    return request.delete<ApiResponse<void>>(`/marks/${id}`)
  },

  /**
   * 删除餐厅的所有标记
   * @param restaurantId 餐厅ID
   */
  deleteRestaurantMarks(restaurantId: string) {
    return request.delete<ApiResponse<void>>(`/marks/restaurant/${restaurantId}`)
  },

  /**
   * 删除餐厅的特定类型标记
   * @param restaurantId 餐厅ID
   * @param markType 标记类型
   */
  deleteRestaurantMarkByType(restaurantId: string, markType: 'today' | 'week') {
    return request.delete<ApiResponse<void>>(`/marks/restaurant/${restaurantId}/${markType}`)
  },

  /**
   * 清空所有标记
   */
  clearAllMarks() {
    return request.delete<ApiResponse<void>>('/marks/clear')
  },

  /**
   * 清空过期标记
   */
  clearExpiredMarks() {
    return request.delete<ApiResponse<void>>('/marks/clear-expired')
  },

  /**
   * 获取标记统计信息
   */
  getMarkStats() {
    return request.get<ApiResponse<MarkStats>>('/marks/stats')
  }
}

export default markApi